<template>
  <view>
    <!-- <DownFile /> -->
    <!-- <WxmlToCanvas /> -->
    <!-- <ScrollList /> -->
  </view>
</template>

<script setup>
const isLoad = ref(false);
onLoad((options) => {
  if (options.shareId) {
    const shareImageData = wx.getStorageSync("shareImage");
    isLoad.value = true;
    // let imgPath = `https://psy-public.obs.myhuaweicloud.com/bpai/static/bpai-wxapp-test-file/chat-list.png`;
    // let filename = imgPath.substring(imgPath.lastIndexOf("/") + 1);
    // wx.downloadFile({
    //   url: imgPath,
    //   filePath: wx.env.USER_DATA_PATH + "/" + filename,
    //   success(res) {
    //     if (res.statusCode === 200) {
    //       const filePath = res.filePath;
    //       console.log("res---", res);
    //       console.log("filePath---", filePath);

    //     //   wx.showShareImageMenu({
    //     //     //分享给朋友
    //     //     path: filePath,
    //     //     success: (res1) => {
    //     //       console.log("分享成功：", res1);
    //     //     },
    //     //     fail: (err) => {
    //     //       console.log("分享取消：", err);
    //     //       uni.navigateBack()
    //     //     },
    //     //   });
    //     }
    //   },
    //   fail() {
    //     console.log("文件下载失败");
    //   },
    //   complete() {
    //     console.log("文件下载操作完成");
    //   },
    // });
    base64ToFilePath(shareImageData);
  }
});
function base64ToFilePath(base64data) {
  //封装的base64转换成临时文件路径的函数
  const base64 = base64data; //base64格式图片
  const time = new Date().getTime();
  const imgPath = wx.env.USER_DATA_PATH + "/" + time + "share_qrcode.png"; //去掉data:image/png;base64,如果图片字符串不含要清空的前缀,可以不执行下行代码.
  const imageData = base64.replace(/^data:image\/\w+;base64,/, "");
  const file = wx.getFileSystemManager();
  file.writeFileSync(imgPath, imageData, "base64");
  wx.showShareImageMenu({
    //分享给朋友
    path: imgPath,
    success: (res) => {
      console.log("分享成功：", res);
    },
    fail: (err) => {
      console.log("分享取消：", err);
    },
    complete() {
      wx.navigateBack({
        delta: 1,
      });
    },
  });
}
</script>
<style lang="scss" scoped></style>
